import requests

class HttpClient:
    def __init__(self, base_url, timeout=10):
        self.base_url = base_url
        self.timeout = timeout
        self.session = requests.Session()

    def request(self, method, path, headers=None, params=None, data=None, json=None, cookies=None):
        url = f"{self.base_url}{path}"
        try:
            response = self.session.request(
                method=method,
                url=url,
                headers=headers,
                params=params,
                data=data,
                json=json,
                cookies=cookies,
                timeout=self.timeout
            )
            response.raise_for_status()
            return response
        except requests.exceptions.RequestException as e:
            raise Exception(f"API request failed: {str(e)}")

    def post_form(self, path, headers=None, data=None, cookies=None):
        if headers is None:
            headers = {}
        headers['Content-Type'] = 'application/x-www-form-urlencoded'
        return self.request('POST', path, headers=headers, data=data, cookies=cookies)

    def post(self, path, headers=None, data=None, json=None):
        return self.request('POST', path, headers=headers, data=data, json=json)

    def get(self, path, headers=None, params=None):
        return self.request('GET', path, headers=headers, params=params)
